var util = require('we7/resource/js/util.js');
App({
    onLaunch: function (res) {
      
     
    
    },
    onShow: function (res) {
     
     
    },
    onHide: function () {
    },
    onError: function (msg) {
        console.log(msg)
    },
    //加载微擎工具类
    util: util,
    //导航菜单，微擎将会自己实现一个导航菜单，结构与小程序导航菜单相同
    //用户信息，sessionid是用户是否登录的凭证
    userInfo: {
        sessionid: null,
    },
    // "tabBar": {
    //     "color": "#999",
    //     "selectedColor": "#f86b4f",
    //     "borderStyle": "#fff",
    //     "backgroundColor": "#fff",
    //     "list": [
    //         {
    //             "pagePath": "/rs_anwser/pages/store/index",
    //             "iconPath": "/rs_anwser/resource/icon/home.png",
    //             "selectedIconPath": "/rs_anwser/resource/icon/home-selected.png",
    //             "text": "首页"
    //         },
    //         {
    //             "pagePath": "/rs_anwser/pages/category/category",
    //             "iconPath": "/rs_anwser/resource/icon/category.png",
    //             "selectedIconPath": "/rs_anwser/resource/icon/category-selected.png",
    //             "text": "分类"
    //         },
    //         {
    //             "pagePath": "/rs_anwser/pages/home/index",
    //             "iconPath": "/rs_anwser/resource/icon/user.png",
    //             "selectedIconPath": "/rs_anwser/resource/icon/user-selected.png",
    //             "text": "我的"
    //         }
    //     ]
    // },
    siteInfo: require('siteinfo.js'),
    userInfo:[],

    subjectPage:{

      /**
 * 获取题目
 */
      getCurrentSubject: function (ele) {
        var subjectList = ele.data.subjectList;
        var current = ele.data.current;
        return subjectList[current];

      },

      /**
       * 更新当前题目状态
       */
      updateCurrentSubject: function (ele,subject) {
        var subjectList = ele.data.subjectList;
        var current = ele.data.current;
        subjectList[current] = subject;
        ele.setData({ subjectList: subjectList });
      },

      getRemainTime:function(s){
        //返回剩余时间
        var m = Math.floor(s/60); 
        var second = s%60;

        return m+':'+second;
      }

    }
    ,
    getOpenId:function(){
      var userInfo = wx.getStorageSync('userInfo');
      return userInfo.openId;
    },
    getUserId:function(){
      var userInfo = wx.getStorageSync('userInfo');
      return userInfo.id;
    },
    getData:function(page,url,p){

      var param = {
        m: 'rs_anwser',
        pIndex: page.data.pageIndex,
      };
     
      param = Object.assign(param,p);
      this.util.request({
        url: url,
        data: param,
        success: function (data) {
          console.log(data);
          if (data.data.data.subjectList.length > 0) {
           
            page.setData({ pageIndex: ++page.data.pageIndex });
            page.setData({
              subjectList: page.data.subjectList.concat(data.data.data.subjectList),
              total:data.data.data.count
            });

          }else{
            wx.showToast({ title: '已经是最后一题了', icon: 'none' });
          }


        }
      })

    },
  addWrong:function(subjectType,subjectId){
      //选错则添加到错题本
      this.util.request(
        {
          url: 'entry/wxapp/addWrongRecord',
          data: {
            m: 'rs_anwser',
            userId: this.getUserId(),
            subjectId: subjectId,
            subjectType: subjectType
          },
          success: function (data) {
            wx.showToast({
              title: '错误，已添加到错题本',
              icon: 'none'
            })
          }
        }
      )
    }  ,
    collect:function(subjectType,subjectId){
      this.util.request(
        {
          url: 'entry/wxapp/addCollectRecord',
          data: {
            m: 'rs_anwser',
            userId: this.getUserId(),
            subjectId: subjectId,
            subjectType: subjectType
          },
          success: function (data) {
            console.log(data);
            wx.showToast({
              title: data.data.message,
              icon: 'none'
            })
          }
        }
      )
    }

    
   
});